package br.com.aeso.bancoCurriculo.model.curriculo.impl;

import java.util.ArrayList;





import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import br.com.aeso.bancoCurriculo.model.comum.negocio.EntidadeNegocio;
import br.com.aeso.bancoCurriculo.model.comum.negocio.impl.ServiceImpl;
import br.com.aeso.bancoCurriculo.model.curriculo.Curriculo;
import br.com.aeso.bancoCurriculo.model.curriculo.CurriculoService;
import br.com.aeso.bancoCurriculo.model.usuario.Usuario;
import br.com.aeso.bancoCurriculo.model.usuario.impl.UsuarioImpl;
import br.com.aeso.bancoCurriculo.model.util.BeanFactory;
import br.com.aeso.bancoCurriculo.model.util.Constantes;

public class CurrriculoServiceImpl extends ServiceImpl implements
		CurriculoService {


	@Override
	public EntidadeNegocio criar() {
		// TODO Auto-generated method stub
		Curriculo curriculo = (Curriculo) BeanFactory
				.getBean(Curriculo.BEAN_NAME);
		curriculo.setUsuario((UsuarioImpl) BeanFactory
				.getBean(Usuario.BEAN_NAME));
		return (EntidadeNegocio) curriculo;
	}

	@Override
	public Class<?> getClasseEntidade() {
		// TODO Auto-generated method stub
		return BeanFactory.getClassPorID(Curriculo.BEAN_NAME);
	}

	@Override
	public ArrayList<CurriculoImpl> pesquisarTodosCurriculos(String nome,String radioButton) {
		ArrayList<CurriculoImpl> todosCurriculos = new ArrayList();

		DetachedCriteria criteria = DetachedCriteria
				.forClass(getClasseEntidade());
		System.out.println(radioButton);
		
		if (!nome.equals("")) {
			System.out.println(radioButton);
			
			 if (radioButton.endsWith(Constantes.FILTRO_ATUACAO_AREA)) {
				criteria.add(Restrictions.ilike("habilidades", nome + "%"));
				todosCurriculos  = (ArrayList<CurriculoImpl>) getHibernateTemplate().findByCriteria(criteria);
				System.out.println("Habilidade Ajax");
	
			}
			 else {
					criteria.add(Restrictions.ilike("nomeCompleto", nome + "%"));
					todosCurriculos  = (ArrayList<CurriculoImpl>) getHibernateTemplate().findByCriteria(criteria);
									System.out.println("Nome Ajax");
					
				}

		}
		else {
			
		todosCurriculos  = (ArrayList<CurriculoImpl>) getHibernateTemplate().findByCriteria(criteria);

			System.out.println("Select * from");
		}
		return todosCurriculos;
	
	}


}
